package com.cjz.rxjavalearn;

import android.app.Application;

import com.cjz.rxjavalearn.api.API;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by cjz on 2016/11/28.
 */

public class RetrofitDemoApp extends Application {

    static RetrofitDemoApp app;

    public RetrofitDemoApp() {
        app = this;
    }

    static public RetrofitDemoApp getApp() {
        return app;
    }


    public Retrofit getRetrofit() {
        return retrofit;
    }

    Retrofit retrofit;
    OkHttpClient client;

    @Override
    public void onCreate() {
        super.onCreate();

        client = new OkHttpClient.Builder()
                .connectTimeout(10_000, TimeUnit.SECONDS)
                .readTimeout(10_000, TimeUnit.SECONDS)
                .writeTimeout(10_000, TimeUnit.SECONDS)
                .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC))
                .build();

        retrofit = new Retrofit.Builder()
                .baseUrl(API.baseUrl)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();

    }
}
